package com.gzz.orchid.main.facade.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;
import java.util.random.RandomGeneratorFactory;

/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/content")
@RequiredArgsConstructor
public class CmsController {
    @GetMapping("/list")
    public String getContentList() {
        //伪随机数生成器, 提供更安全的随机算法
        RandomGeneratorFactory.of("L64X128MixRandom").create();
        //
        // JDK 17新增API示例
        // 1. 新的日期周期格式
        //        Period period = Period.parse("P2Y3M4D");
        //        // 2. 增强的伪随机数算法
        //        RandomGeneratorFactory<RandomGenerator> factory =
        //                RandomGeneratorFactory.of("L64X128MixRandom");
        //        RandomGenerator random = factory.create();
        //        // 3. 矢量API（孵化阶段）
        //        FloatVector a = FloatVector.fromArray(FloatVector.SPECIES_256, arr1, 0);
        //        FloatVector b = FloatVector.fromArray(FloatVector.SPECIES_256, arr2, 0);
        //        FloatVector c = a.mul(b).add(b);
        return "Hello World - Content" + " - " + LocalDateTime.now();
    }

    @GetMapping("/detail")
    public List<String> getContentDetail() {
        List<String> dates = List.of("2023-01-01", "2023-01-02", "2023-01-03"
                , "2023-01-04", "2023-01-05", "2023-01-06", "2023-01-07"
                , "2023-01-08", "2023-01-09", "2023-01-10");
        return dates
                .stream()
                .map(date -> "Content Detail - " + date)
                //                .mapMulti((sentence,  consumer)->{
                //                  for(String word: sentence.split(" ")){
                //                      consumer.accept("Content Detail - " + word);
                //                  }
                //                })
                .toList();
    }
}
